import React from 'react';
import { Redirect } from 'react-router-dom';
/* 懒加载页面组件 */
const Login = React.lazy((_) => import('../pages/login/login'));
const Index = React.lazy((_) => import('../pages/main/index'));
const Notfound = React.lazy((_) => import('../pages/not-found/not-found'));

const Main = React.lazy((_) => import('../pages/main/subPages/main/main'));
const Category = React.lazy((_) =>
  import('../pages/main/subPages/category/category'),
);
const Dashboard = React.lazy((_) =>
  import('../pages/main/subPages/dashboard/dashboard'),
);
const Department = React.lazy((_) =>
  import('../pages/main/subPages/department/department'),
);
const Goods = React.lazy((_) => import('../pages/main/subPages/goods/goods'));
const Role = React.lazy((_) => import('../pages/main/subPages/role/role'));
const User = React.lazy((_) => import('../pages/main/subPages/user/user'));

const routes = [
  {
    path: '/',
    exact: true,
    render: () => <Redirect to="/login" />,
  },
  {
    path: '/main',
    component: Index,
    routes: [
      {
        path: '/main',
        exact: true,
        render: () => <Redirect to="/main/category" />,
      },
      {
        path: '/main/main',
        exact: true,
        component: Main,
      },
      {
        path: '/main/category',
        exact: true,
        component: Category,
      },
      {
        path: '/main/dashboard',
        exact: true,
        component: Dashboard,
      },
      {
        path: '/main/department',
        exact: true,
        component: Department,
      },
      {
        path: '/main/goods',
        exact: true,
        component: Goods,
      },
      {
        path: '/main/role',
        exact: true,
        component: Role,
      },
      {
        path: '/main/user',
        exact: true,
        component: User,
      },
    ],
  },
  {
    path: '/login',
    component: Login,
  },
  {
    component: Notfound,
  },
];

export default routes;
